package com.example.shopping.controller;

import com.example.shopping.common.consts.MessageEnum;
import com.example.shopping.common.consts.ResultEnum;
import com.example.shopping.common.response.RestResponse;
import com.example.shopping.pojo.domain.CarBean;
import com.example.shopping.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Dream
 * @version 1.0
 * @date 2020/11/9 18:45
 */
@RestController
@RequestMapping(value="car")
public class CarController {
    @Autowired
    private CarService carService;

    /**
     * 查询购物车
     * @param userXh
     * @return
     */
    @RequestMapping(value="/getByXh")
    public RestResponse getByxh(@RequestParam(value="userXh") String userXh){
        return new RestResponse(ResultEnum.SUCCESS,carService.getByXh(userXh));
    }

    /**
     * 添加购物车
     * @param carBean
     * @return
     */
    @RequestMapping(value="/add")
    public RestResponse addCart(@Validated @RequestBody CarBean carBean){
        return new RestResponse(ResultEnum.SUCCESS,carService.addCart(carBean));
    }

    /**
     * 删除购物车
     * @param goodsId
     * @return
     */
    @RequestMapping(value="/deleteById")
    public RestResponse removeGoods(@RequestParam(value="goodsId") Integer goodsId){
        carService.removeById(goodsId);
        return new RestResponse(ResultEnum.SUCCESS, MessageEnum.REMOVE_SUCCESS);
    }
}
